package com.jixiantubu.adapter;

import image.SmartImageView;

import java.util.ArrayList;
import java.util.List;

import com.example.jixiantubu.R;
import com.jixiantubu.bean.Travelsbean;
import com.jixiantubu.index.CeShiActivity;
import com.jixiantubu.jinnang.JinNang_YouJi_JuTiNeiRong;
import com.jixiantubu.jinnang.JinNang_YouJi_MuLu;
import com.jixiantubu.util.EllipsizeText;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.BitmapUtils;

import android.R.string;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.TwoLineListItem;

public class YouJiAdapter extends BaseAdapter {
	Context context;// 上下文
	List<Travelsbean> list = new ArrayList<Travelsbean>();// 定义集合Travelsbean
	LayoutInflater mInflater;// 用来绑定布局
	ViewHolder viewHolder;// 初始化控件
	BitmapUtils bitmapUtils;

	public YouJiAdapter(Context context, List<Travelsbean> list) {
		super();
		this.context = context;
		this.list = list;

		// 绑定上下文
		mInflater = LayoutInflater.from(context);
	}

	public List<Travelsbean> getList() {
		return list;
	}

	public void setList(List<Travelsbean> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 2;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public View getView(final int arg0, View arg1, ViewGroup arg2) {
		Log.e("胡椒dddddddddd", String.valueOf(getCount()));
		viewHolder = new ViewHolder();
		if (arg1 == null) {// 如果界面是空的 （arg1是布局界面）

			// 使用mInflater绑定布局youji_item
			arg1 = mInflater.inflate(R.layout.jinnang_youji_item, null);
			// 初始化布局内的各个控件
			viewHolder.imageView1 = (SmartImageView) arg1
					.findViewById(R.id.youji_user_touxiang);
			viewHolder.textView = (TextView) arg1
					.findViewById(R.id.youji_user_name);
			viewHolder.t_title = (TextView) arg1
					.findViewById(R.id.youji_title);
			viewHolder.user_time = (TextView) arg1
					.findViewById(R.id.youji_time);
			viewHolder.textView1 = (EllipsizeText) arg1
					.findViewById(R.id.youji_user_neirongjianjie);
			viewHolder.imageView = (SmartImageView) arg1
					.findViewById(R.id.youji_user_image);
			// 添加界面的各个元素
			arg1.setTag(viewHolder);
		} else {// 如果界面不是空
			viewHolder = (ViewHolder) arg1.getTag();// 得到界面
		}
		// 得到数据库的网址+list集合中arg0的下标里的User_imgPath()；
		String url = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ list.get(arg0).getUser_imgPath();
		Log.e("dajshdjaskhd", url);
		 viewHolder.imageView1.setstyle("circle");
		viewHolder.imageView1.setImageUrl(url, R.drawable.error, R.drawable.loding);// 得到用户头像
		// 单击头像跳到用户的游记目录界面
		viewHolder.imageView1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg5) {
				Intent intent = new Intent(context, JinNang_YouJi_MuLu.class);
				intent.putExtra("mulu", list.get(arg0));
				Log.e("qqqqqqqqqqq11111@!!", list.get(arg0).toString());
				context.startActivity(intent);
			}
		});
		String url1 = "http://" + MyApplication.getIP() + ":8080/Jinnang/img/"
				+ list.get(arg0).getPl_path().get(0).getpl_path();
		//viewHolder.imageView.setImageUrl(url1);// 得到用户的图片
		viewHolder.imageView.setImageUrl(url1, R.drawable.error, R.drawable.loding);
		viewHolder.imageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg6) {
				Intent intent = new Intent(context,
						JinNang_YouJi_JuTiNeiRong.class);
				intent.putExtra("neirong", list.get(arg0));
				Log.e("aaaaaaaaaa@@@ccccccccc", list.get(arg0).toString());
				context.startActivity(intent);
			}
		});
		// 得到用户昵称
		viewHolder.textView.setText(list.get(arg0).getUser_nickname());
		// 得到用户的语句简介(游记标题)
		viewHolder.textView1.setText(list.get(arg0).getT_content());
		viewHolder.user_time.setText(list.get(arg0).getT_time());
		viewHolder.t_title.setText(list.get(arg0).getT_tittle());
		//MyApplication.otherusername=String.valueOf(list.get(arg0).getUser_id());
		//Log.e("其他人的用户名", MyApplication.otherusername); 
		return arg1;
	}

	public class ViewHolder {
		image.SmartImageView imageView;
		TextView textView, user_time, t_title;
		EllipsizeText textView1;
		image.SmartImageView imageView1;

	}
}
